package neusoft.yuejian_11.activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;

import java.util.List;

import neusoft.yuejian_11.adapter.DuijiangAdapter;
import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.DuijiangBean;
import neusoft.yuejian_11.fragment.SpaceItemDecoration;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.UserModel;
import neusoft.yuejian_11.R;

//兑奖记录列表（已改）
public class DuijiangActivity extends BaseActivity implements RetrofitListener {
    private RecyclerView recyclerView;
    private DuijiangAdapter adapter;
    private ImageButton imageButtonBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_duijiang);
        initView();
        initData();

        //返回前一页
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    private void initData() {
        UserModel userModel=new UserModel();
        userModel.getMyDuijiang(getU_id(),this);
    }

    private void initView() {
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);
        recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
    }

    @Override
    public void onSuccess(Object o, int flag) {
        List<DuijiangBean> duijiangBean=(List<DuijiangBean>)o;
        adapter = new DuijiangAdapter(DuijiangActivity.this, duijiangBean);
        LinearLayoutManager layoutManager = new LinearLayoutManager(DuijiangActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new SpaceItemDecoration(8));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }

    @Override
    public void onFail() {

    }
}
